/*     */ package com.yc.web.export;
/*     */ 
/*     */ import com.yc.dao.query.QueryBO;
/*     */ import com.yc.dao.station.GeographicalenvDAO;
/*     */ import com.yc.service.MagnifierService;
/*     */ import com.yc.service.station.AcdcDistributionService;
/*     */ import com.yc.service.station.AirconditionService;
/*     */ import com.yc.service.station.AntennaFeederService;
/*     */ import com.yc.service.station.BTSService;
/*     */ import com.yc.service.station.BathunderService;
/*     */ import com.yc.service.station.DynamoService;
/*     */ import com.yc.service.station.EnvMontorService;
/*     */ import com.yc.service.station.FireExtinGuisherService;
/*     */ import com.yc.service.station.IronTowerService;
/*     */ import com.yc.service.station.MachineRoomService;
/*     */ import com.yc.service.station.MainssupplyService;
/*     */ import com.yc.service.station.PowerBoxService;
/*     */ import com.yc.service.station.PowerSupplyService;
/*     */ import com.yc.service.station.StorageBatteryService;
/*     */ import com.yc.service.station.TrafficInfoService;
/*     */ import com.yc.service.station.TransfersService;
/*     */ import com.yc.service.station.TransformerService;
/*     */ import com.yc.web.station.IExportService;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.ServletOutputStream;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.poi.hssf.usermodel.HSSFSheet;
/*     */ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/*     */ 
/*     */ public class ExportServlet extends HttpServlet
/*     */ {
/*     */   public String createDownLoadPath()
/*     */   {
/*  47 */     String path = getServletContext().getRealPath("/");
/*  48 */     path = path + "downloadtemp" + File.separator;
/*  49 */     if (!new File(path).isDirectory()) {
/*  50 */       File file = new File(path);
/*  51 */       file.mkdir();
/*     */     }
/*  53 */     return path;
/*     */   }
/*     */ 
/*     */   private IExportService getExportService(int tableNo)
/*     */   {
/*  59 */     IExportService exportService = null;
/*  60 */     switch (tableNo)
/*     */     {
/*     */     case 1:
/*  63 */       exportService = new BTSService();
/*  64 */       break;
/*     */     case 2:
/*  66 */       exportService = new MagnifierService();
/*  67 */       break;
/*     */     case 3:
/*  69 */       exportService = new PowerBoxService();
/*  70 */       break;
/*     */     case 4:
/*  72 */       exportService = new StorageBatteryService();
/*  73 */       break;
/*     */     case 5:
/*  75 */       exportService = new AirconditionService();
/*  76 */       break;
/*     */     case 6:
/*  78 */       exportService = new FireExtinGuisherService();
/*  79 */       break;
/*     */     case 7:
/*  81 */       exportService = new BathunderService();
/*  82 */       break;
/*     */     case 8:
/*  84 */       exportService = new EnvMontorService();
/*  85 */       break;
/*     */     case 9:
/*  87 */       exportService = new DynamoService();
/*  88 */       break;
/*     */     case 10:
/*  90 */       exportService = new AcdcDistributionService();
/*  91 */       break;
/*     */     case 11:
/*  93 */       exportService = new TransformerService();
/*  94 */       break;
/*     */     case 12:
/*  96 */       exportService = new TransfersService();
/*  97 */       break;
/*     */     case 13:
/*  99 */       exportService = new MainssupplyService();
/* 100 */       break;
/*     */     case 14:
/* 102 */       exportService = new AntennaFeederService();
/* 103 */       break;
/*     */     case 15:
/* 105 */       exportService = new IronTowerService();
/* 106 */       break;
/*     */     case 16:
/* 108 */       exportService = new MachineRoomService();
/* 109 */       break;
/*     */     case 17:
/* 111 */       exportService = new PowerSupplyService();
/* 112 */       break;
/*     */     case 18:
/* 114 */       exportService = new TrafficInfoService();
/* 115 */       break;
/*     */     case 19:
/* 117 */       exportService = new GeographicalenvDAO();
/* 118 */       break;
/*     */     default:
/* 120 */       exportService = new BTSService();
/*     */     }
/* 122 */     return exportService;
/*     */   }
/*     */ 
/*     */   private List getList(int tableNo, String strBtsName, String strRegistBeginTime, String strRegistEndTime) {
/* 126 */     IExportService exportService = getExportService(tableNo);
/* 127 */     return exportService.export(strBtsName, strRegistBeginTime, strRegistEndTime);
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 133 */     String strBtsName = request.getParameter("btsName");
/* 134 */     String strTableNo = request.getParameter("tableNo");
/* 135 */     String registBeginTime = request.getParameter("registBeginTime");
/* 136 */     String registEndTime = request.getParameter("registEndTime");
/* 137 */     QueryBO bo = (QueryBO)Contants.queryMap.get(strTableNo);
/*     */ 
/* 139 */     String fileName = bo.getName() + ".xls";
/* 140 */     String path = createDownLoadPath();
/* 141 */     FileOutputStream fileOut = null;
/*     */     try
/*     */     {
/* 144 */       HSSFWorkbook workbook = new HSSFWorkbook();
/* 145 */       HSSFSheet sheet = workbook.createSheet(bo.getName());
/* 146 */       List list = getList(Integer.parseInt(strTableNo), strBtsName, registBeginTime, registEndTime);
/* 147 */       ExportUtil.wirteToExcel(sheet, list, Integer.parseInt(strTableNo));
/* 148 */       fileOut = new FileOutputStream(path + fileName);
/* 149 */       workbook.write(fileOut);
/* 150 */       fileOut.flush();
/* 151 */       fileOut.close();
/*     */     }
/*     */     catch (Exception ioe)
/*     */     {
/* 155 */       ioe.printStackTrace();
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/* 160 */       File file = new File(path + fileName);
/* 161 */       ServletOutputStream servletOutputStream = response.getOutputStream();
/*     */ 
/* 163 */       fileName = URLEncoder.encode(fileName, "UTF-8");
/* 164 */       response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
/* 165 */       response.setContentLength((int)file.length());
/* 166 */       response.setContentType("application/x-download;charset=UTF-8");
/*     */ 
/* 168 */       byte[] b = new byte[1024];
/* 169 */       int i = 0;
/* 170 */       FileInputStream fis = new FileInputStream(file);
/* 171 */       while ((i = fis.read(b)) > 0)
/*     */       {
/* 173 */         servletOutputStream.write(b, 0, i);
/*     */       }
/* 175 */       servletOutputStream.flush();
/*     */ 
/* 177 */       file.delete();
/*     */     }
/*     */     catch (IOException ioe) {
/* 180 */       ioe.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 188 */     doPost(request, response);
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.web.export.ExportServlet
 * JD-Core Version:    0.6.2
 */